import com.dmotiko.mirador.*
import com.dmotiko.general.*
import com.dmotiko.util.*
import mx.utils.Delegate;

class MiradorSite
extends WebSite {
	
	//CONSTANTS
	public static var CONTEXT_CHANGED:String = "miradorsite_contextchanged";
	public static var DANBRO:String = "DAMBROSITE";
	public static var MIRADOR:String = "MIRADORSITE";
	public static var PREHOME:String = "_PREHOME";
	public static var HOME:String = "_HOME";
	public static var QUIENES_SOMOS:String = "_QUIENES_SOMOS";
	public static var NUESTROS_SALONES:String = "_NUESTROS_SALONES";
	public static var SERVICIOS_BODAS:String = "_SERVICIOS_BODAS";
	public static var SERVICIOS_QUINCE:String = "_SERVICIOS_QUINCE";
	public static var SERVICIOS_BARMITZVA:String = "_SERVICIOS_BARMITZVA";
	public static var EVENTOS:String = "_EVENTOS";
	public static var ORGANIZACION:String = "_ORGANIZACION";
	public static var COMUNIQUESE:String = "_COMUNIQUESE";
	public static var UBICACION:String = "_UBICACION";
		
	private var mcLoader:MovieClipLoader;
	private var sContext:String;
	
	//SECTIONS
	private var mcBack:MovieClip;
	private var mcIntro:MovieClip;
	private var mcHome:MovieClip;
	private var mcHomeMirador:MovieClip;
	private var mcHomeDanbro:MovieClip;
	private var mcQuienesSomos:MovieClip;
	private var mcNuestrosSalones:MovieClip;
	private var mcButtonBar:MiradorMainBtnBar;
	private var mcOrganizacionEventos:MovieClip;
	private var mcServiciosBodas:MovieClip;
	private var mcServiciosFiestas15:MovieClip;
	private var mcServiciosBarMitzva:MovieClip;
	private var mcServiciosEventos:MovieClip;
	private var mcContactoComuniquese:MovieClip;
	private var mcContactoUbicacion:MovieClip;
	
	//XML
	private var roomsLoader:MiradorRoomsLoader;
	private var rooms:Object;
	private var clientsLoader:MiradorClientsLoader;
	private var clients:Array;
	private var mcSound:MovieClip;
	private var miradorSound:MiradorSound;
					
	public static function init(timeline:MovieClip){
		if (!app) {
			app = new MiradorSite(timeline);
			app.initSite();
		}
	}
	
	public static function getApp():MiradorSite {
		return MiradorSite(app);
	}
	
	private function MiradorSite(timeline){
		super(timeline);
	}
	
	private function initSite(){
		this.setSection( MiradorSite.PREHOME );
		initStage();
		loadExternalData();
		//initSections();
	}
	
	private function initStage():Void {
		Stage.align = (_root.swf_stageAlign) ? _root.swf_stageAlign : "TL";
		Stage.scaleMode = (_root.swf_scaleMode) ? _root.swf_scaleMode : "noScale";
	}
	
	private function loadExternalData():Void {
		clientsLoader = new MiradorClientsLoader();
		clientsLoader.addEventListener( DataXMLLoader.DATA_LOADED, Delegate.create(this, clientsLoaded) );
		
		roomsLoader = new MiradorRoomsLoader();
		roomsLoader.run("rooms.xml");
		roomsLoader.addEventListener( DataXMLLoader.DATA_LOADED,  Delegate.create(this, roomsLoaded) );
		
	}
	
	private function clientsLoaded(e ):Void {
		clients = Array(e.data.client);
	}
	
	private function roomsLoaded( e ):Void {
		rooms = e.data;
		initSections();
	}
		
	private function initSections():Void {
		mcBack = this.timeline.attachMovie("MiradorBack", "mcBack", this.timeline.getNextHighestDepth());
		
		mcIntro = this.timeline.createEmptyMovieClip( "mcIntro", this.timeline.getNextHighestDepth() );
		mcHomeMirador = this.timeline.createEmptyMovieClip( "mcHomeMirador", this.timeline.getNextHighestDepth() );
		mcHomeDanbro = this.timeline.createEmptyMovieClip( "mcHomeDanbro", this.timeline.getNextHighestDepth() );
		mcQuienesSomos = this.timeline.createEmptyMovieClip( "mcQuienesSomos", this.timeline.getNextHighestDepth() );
		mcNuestrosSalones = this.timeline.createEmptyMovieClip( "mcNuestrosSalones", this.timeline.getNextHighestDepth() );
		mcOrganizacionEventos = this.timeline.createEmptyMovieClip( "mcOrganizacionEventos", this.timeline.getNextHighestDepth() );
		mcServiciosBodas = this.timeline.createEmptyMovieClip( "mcServiciosBodas", this.timeline.getNextHighestDepth() );
		mcServiciosFiestas15 = this.timeline.createEmptyMovieClip( "mcServiciosFiestas15", this.timeline.getNextHighestDepth() );		
		mcServiciosBarMitzva = this.timeline.createEmptyMovieClip( "mcServiciosBarMitzva", this.timeline.getNextHighestDepth() );
		mcServiciosEventos = this.timeline.createEmptyMovieClip( "mcServiciosEventos", this.timeline.getNextHighestDepth() );
		mcContactoComuniquese = this.timeline.createEmptyMovieClip( "mcContactoComuniquese", this.timeline.getNextHighestDepth() );
		mcContactoUbicacion = this.timeline.createEmptyMovieClip( "mcContactoUbicacion", this.timeline.getNextHighestDepth() );
		mcSound = this.timeline.createEmptyMovieClip( "mcSound", this.timeline.getNextHighestDepth() );
		mcHome = this.timeline.createEmptyMovieClip( "mcHome", this.timeline.getNextHighestDepth() );
		
		mcLoader = new MovieClipLoader();
		
		mcLoader.loadClip( "prehome.swf", mcIntro);
		mcLoader.loadClip( "home.swf", mcHome);
		mcLoader.loadClip( "homemirador.swf", mcHomeMirador);
		mcLoader.loadClip( "homedanbro.swf", mcHomeDanbro);
		mcLoader.loadClip( "quienesSomos.swf", mcQuienesSomos);
		mcLoader.loadClip( "nuestrosSalones.swf", mcNuestrosSalones);
		mcLoader.loadClip( "organizacionEventos.swf", mcOrganizacionEventos);
		mcLoader.loadClip( "serviciosBodas.swf", mcServiciosBodas);
		mcLoader.loadClip( "serviciosFiestas15.swf", mcServiciosFiestas15);
		mcLoader.loadClip( "serviciosBarMitzva.swf", mcServiciosBarMitzva);
		mcLoader.loadClip( "serviciosEventos.swf", mcServiciosEventos);
		mcLoader.loadClip( "contactoComuniquese.swf", mcContactoComuniquese);
		mcLoader.loadClip( "contactoUbicacion.swf", mcContactoUbicacion);
		mcLoader.loadClip( "sound2.swf", mcSound);
		mcLoader.addListener(this);
				
		return;
	}
	
	public function onLoadInit( target ) {
		//trace("MiradorSite | onLoadInit= " + target);
	}
	
	public function setMiradorSound( ms:MiradorSound ):Void {
		miradorSound = ms;
	}
	public function getMiradorSound():MiradorSound {
		return miradorSound;
	}
	
	public function getContext():String { return sContext; }
	
	public function setContext(value:String):Void {
		var last:String = this.sContext;
		sContext = value;
		dispatchEvent( { target: this, type: MiradorSite.CONTEXT_CHANGED, last: last, context: sContext } );
		
	}
	
	public function getHome():MovieClip { return mcHome; }
	public function getIntro():MovieClip { return mcIntro; }
	
	public function getButtonBar():MiradorMainBtnBar { return mcButtonBar; }
	
	public function setButtonBar(value:MiradorMainBtnBar):Void {
		mcButtonBar = value;
	}
	
	public function getRooms():Object { return rooms; }
	public function getClients():Array { return clients; }
	
}